﻿Imports System.ComponentModel

Partial Public Class FrmMain

    Private m_BackgroundWorker As BackgroundWorker = Nothing
    Private m_ContextMenuStrip1 As ContextMenuStrip = Nothing
    Private m_ContextMenuStrip2 As ContextMenuStrip = Nothing
    Private m_NotifyIcon As NotifyIcon = Nothing

    Dim m_miSetting As ToolStripMenuItem = Nothing
    Dim m_miBackup As ToolStripMenuItem = Nothing
    Dim m_miRestore As ToolStripMenuItem = Nothing
    Dim m_miShowOrHide As ToolStripMenuItem = Nothing
    Dim m_miExit2 As ToolStripMenuItem = Nothing

    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub initializeComponent()
        Me.m_BackgroundWorker = New BackgroundWorker()
        With Me.m_BackgroundWorker
            AddHandler .DoWork, AddressOf Me.BackgroundWorker_DoWork
            AddHandler .RunWorkerCompleted, AddressOf Me.BackgroundWorker_RunWorkerCompleted
        End With

        Me.m_ContextMenuStrip2 = New ContextMenuStrip()
        Me.m_NotifyIcon = New NotifyIcon() With {.Icon = My.Resources.Icon, _
                                                 .Visible = True, _
                                                 .ContextMenuStrip = Me.m_ContextMenuStrip2}
        AddHandler Me.m_NotifyIcon.DoubleClick, AddressOf Me.NotifyIcon_DoubleClick
        m_miSetting = New ToolStripMenuItem() With {.Text = "设置"}
        AddHandler m_miSetting.Click, AddressOf Me.miSetting_Click
        Dim _ToolStripSeparator1 As New System.Windows.Forms.ToolStripSeparator
        m_miBackup = New ToolStripMenuItem() With {.Text = "备份"}
        AddHandler m_miBackup.Click, AddressOf Me.miBackup_Click
        m_miRestore = New ToolStripMenuItem() With {.Text = "还原"}
        AddHandler m_miRestore.Click, AddressOf Me.miRestore_Click
        Dim _ToolStripSeparator2 As New System.Windows.Forms.ToolStripSeparator
        m_miShowOrHide = New ToolStripMenuItem() With {.Text = "隐藏"}
        AddHandler m_miShowOrHide.Click, AddressOf Me.miShowOrHide_Click
        Dim _ToolStripSeparator3 As New System.Windows.Forms.ToolStripSeparator
        m_miExit2 = New System.Windows.Forms.ToolStripMenuItem() With {.Text = "退出"}
        AddHandler m_miExit2.Click, AddressOf Me.miExit_Click
        Me.m_ContextMenuStrip2.Items.AddRange(New ToolStripItem() {m_miSetting, _ToolStripSeparator1, m_miBackup, m_miRestore, _ToolStripSeparator2, m_miShowOrHide, _ToolStripSeparator3, m_miExit2})

    End Sub

    Private Sub BackgroundWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
        Me.BindData()
    End Sub

    Private Sub BackgroundWorker_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs)
        Console.WriteLine(e.ProgressPercentage)
    End Sub

    Private Sub BackgroundWorker_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)
        Me.m_Trochoid.Show()
    End Sub

#Region "MainMenu事件"

    'Private Sub miAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    Dim _FrmItem As New frmItem()
    '    _FrmItem.Op = Operate.Add
    '    If _FrmItem.ShowDialog() = Windows.Forms.DialogResult.OK Then
    '        Me.m_BackgroundWorker.RunWorkerAsync()
    '    End If
    '    _FrmItem.Dispose() : _FrmItem = Nothing
    'End Sub

    'Private Sub miBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    Dim _SaveFileDialog As New SaveFileDialog()
    '    _SaveFileDialog.Filter = "XML文件|*.xml"
    '    _SaveFileDialog.FileName = String.Concat("QuickStartupTool_", DateTime.Now.ToString("yyyyMMdd"))
    '    If _SaveFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
    '        System.IO.File.Copy(o_ConfigPath, _SaveFileDialog.FileName)
    '        MsgBox("备份成功")
    '    End If
    'End Sub

    'Private Sub miRestore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    Dim _OpenFileDialog As New OpenFileDialog()
    '    _OpenFileDialog.Filter = "XML文件|*.xml"
    '    If _OpenFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
    '        System.IO.File.Copy(_OpenFileDialog.FileName, o_ConfigPath, True)

    '        Me.m_BackgroundWorker.RunWorkerAsync()
    '    End If
    'End Sub

    Private Sub miSetting_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim _FrmSetting As New FrmSetting() With {.Trochoid = Me.m_Trochoid}
        _FrmSetting.Show()
        Me.FormHide()
    End Sub

    Private Sub miBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim _SaveFileDialog As New SaveFileDialog()
        _SaveFileDialog.Filter = "XML文件|*.xml"
        _SaveFileDialog.FileName = String.Concat("QuickStartupTool_", DateTime.Now.ToString("yyyyMMdd"))
        If _SaveFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
            System.IO.File.Copy(o_ConfigPath, _SaveFileDialog.FileName)
            MsgBox("备份成功")
        End If
    End Sub

    Private Sub miRestore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim _OpenFileDialog As New OpenFileDialog()
        _OpenFileDialog.Filter = "XML文件|*.xml"
        If _OpenFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
            System.IO.File.Copy(_OpenFileDialog.FileName, o_ConfigPath, True)

            If Me.Visible Then
                Me.m_BackgroundWorker.RunWorkerAsync()
            End If
        End If
    End Sub

    Private Sub miShowOrHide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Me.Visible Then
            Me.FormHide()
        Else
            Me.FormShow()
        End If
    End Sub

    Private Sub miExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        System.Environment.Exit(System.Environment.ExitCode)
    End Sub

#End Region

    Private Sub NotifyIcon_DoubleClick(ByVal sender As Object, ByVal e As EventArgs)
        If Me.Visible = False Then
            Me.FormShow()
        Else
            Me.FormHide()
        End If
    End Sub

End Class
